new Vue({
    el: '#app',
    data() {
        return {
            form: {
                Data:"base_components_info",
                Type:"TableName",
                Components_Name:'',
                page: 1,			//页数
                limit: 10,			//每页数据条数
            },
            total: 0,
            tableData: [],		//表格数据
        }
    },
    mounted() {
        // this.getList(this.form)
    },
    methods: {
        onSerach() {			//查询方法
            this.form.page = 1;
            this.getList(this.form)
        },
        Add() {
            window.location.href = './add.html'
        },
        handleSizeChange(val) {
            this.form.page = 1;
            this.form.limit = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.page = val;
            this.getList(this.form)
        },
        getList(data) {//换页方法
            let that = this
            $.ajax({
                type: 'POST',
                url: `${BASE_URL}/getGeneralQueryAction?grant_type=tourist`,
                data:{
                    ...data,
                    Filter:JSON.stringify([{
                        Key:'Row_Status',
                        Value:'0'
                    },{
                        Key:'Components_Name',
                        Value:data.Components_Name,
                        Vague:true,
                    }]),
                    Page:JSON.stringify({
                        page:data.page,
                        limit:data.limit
                    })
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                success: function (Result) {
                    if (Result.Status == 'success') {
                        that.tableData = Result.Data;
                        that.total = Result.total;
                    }
                },
                dataType: "json"
            });
        },
        Edit(App_ID) {
            sessionStorage.setItem("App_ID", App_ID)
            window.location.href = './edit.html?App_ID=' + App_ID
        },
        Remove(row) {
            const _this = this
            this.$confirm('警告！此操作将删除该组件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                $.ajax({
                    url: `${BASE_URL}/DeleteAction?token=${$.cookie('token')}`,
                    type: 'POST',
                    data: {
                        TableName: 'page_about_us_menu_info',
                        Primary_Key: row.Page_AboutUs_Menu_SerialNumber,
                        Primary_Key_Name: 'Page_AboutUs_Menu_SerialNumber',
                        Operation_Name: '删除组件'
                    },
                    success: function (res) {
                        if (res.Status == 'success') {
                            _this.getList(_this.form);
                            _this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                        }
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'warning',
                    message: '已取消操作'
                });
            });
        }
    },
})